package com.udaos.modules.train.services;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import com.udaos.common.base.Service;
import com.udaos.models.train.Ud_train_contract;
import com.udaos.models.ud.Ud_wx_user;
import com.udaos.modules.customer.services.UdWxUserService;
import com.udaos.modules.trainer.services.UdTrainerService;
import com.udaos.modules.wx.services.ApiWxTemplateService;
/**
 * 培训协议
 * @author mutaotao
 *
 */
@IocBean(args = {"refer:dao"})
public class UdTrainContractService extends Service<Ud_train_contract>{

	@Inject
	private UdWxUserService udWxUserService;
	@Inject
	private ApiWxTemplateService templateService;
	@Inject
	private UdTrainerService trainerService;
	public UdTrainContractService(Dao dao){
		super(dao);
	}

	/**
	 * 发送分配教练模板消息给用户
	 * @param contract
	 */
	public void sendToUser(Ud_train_contract contract) {
		//获取其报名公众号信息,根据openId获取其所属微信平台
		Cnd cnd=Cnd.NEW();
		cnd.and("customer_id", "=", contract.getCustomer_id());
		cnd.and("company_id", "=", contract.getCompany_id());
		Ud_wx_user wx_user=udWxUserService.fetch(cnd);
		String appid=wx_user.getAppid();
		String openId=wx_user.getOpenid();
		//获取教练
		
		boolean b=templateService.sendFpjlTemplate(appid, openId,trainerService.fetch(contract.getTrainer_id()).getName(),"",null,trainerService.fetch(contract.getTrainer_id()).getMobile());
		
	}
}
